#include "../../Header/Entity/Background.h"

Background::Background()
:Entity()
{

}

Background::~Background()
{

}

void Background::Init()
{
	Vertex verticesData[3];

	verticesData[0].m_Pos.x = 0.0f;  verticesData[0].m_Pos.y = 0.5f;  verticesData[0].m_Pos.z = 0.0f;
	verticesData[1].m_Pos.x = -0.5f;  verticesData[1].m_Pos.y = -0.5f;  verticesData[1].m_Pos.z = 0.0f;
	verticesData[2].m_Pos.x = 0.5f;  verticesData[2].m_Pos.y = -0.5f;  verticesData[2].m_Pos.z = 0.0f;

	//buffer object
	GLuint vboId;
	glGenBuffers(1, &vboId);
	glBindBuffer(GL_ARRAY_BUFFER, vboId);
	glBufferData(GL_ARRAY_BUFFER, sizeof(verticesData), verticesData, GL_STATIC_DRAW);
	glBindBuffer(GL_ARRAY_BUFFER, 0);
	Mesh* mesh = new Mesh();
	mesh->m_VBO = vboId;
	m_Meshes.push_back(mesh);

	m_Shader = new Shader();
	m_Shader->Init("../../Resources/Shaders/Triangle.vsh", "../../Resources/Shaders/Triangle.fsh");
}

void Background::Destroy()
{

}

void Background::Update(__float_)
{

}

void Background::Draw()
{
	glUseProgram(m_Shader->m_Program);

	glBindBuffer(GL_ARRAY_BUFFER, m_Meshes.at(0)->m_VBO);


	if (m_Shader->m_Pos != -1)
	{
		glEnableVertexAttribArray(m_Shader->m_Pos);
		glVertexAttribPointer(m_Shader->m_Pos, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), 0);
	}

	glDrawArrays(GL_TRIANGLES, 0, 3);

	glBindBuffer(GL_ARRAY_BUFFER, 0);
}